@extends('backend.layouts.app')

@section('title', $title =  '代理提款' )

@section('breadcrumb')
    <a href="">系统设置</a>
    <a href="">代理管理</a>
    <a href="">{{$title}}</a>
@endsection

@section('content')
    <div class="layui-container" >

        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>{{ $title }}</legend>
        </fieldset>
        @if(\Auth::user()->type==0)
            <form class="layui-form layui-form-pane" method="GET"
                  action="{{ route('agent.withdrawal') }}">
                {{ csrf_field() }}
                <div class="layui-inline">
                    <label class="layui-form-label">网站选择</label>
                    <div class="layui-input-inline">
                        <select name="agent_id" lay-verify="required" lay-search="">
                            <option value="">直接选择或搜索选择</option>
                            @foreach($agents as $value)
                                <option value="{{$value->id}}">{{$value->name}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
                <button class="layui-btn" lay-submit="" lay-filter="demo1">提交</button>
            </form>
        @endif
        @if(isset($agent))
            <form class="layui-form layui-form-pane" method="POST"
                  action="{{route('agent.withdrawal.store',[$agent->id])}}">
                {{ csrf_field() }}

                <div class="layui-col-md12 ">
                    <div class="layui-card layui-bg-cyan">
                        <div class="layui-card-header layui-bg-cyan">{{$agent->name}}代理信息</div>
                        <div class="layui-card-body layui-bg-cyan">
                            余额：{{$agent->money}}<br>
                            比率：{{$agent->rate}}<br>
                            默认到账方式：{{$agent->pay_type}}<br>
                            默认提款账号：{{$agent->account}}<br>
                            默认提款账号户名：{{$agent->account_real_name}}<br>
                            提款账号开户地址：{{$agent->account_address}}<br>
                        </div>
                    </div>

                    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                        <legend>提款及修改提款信息</legend>
                    </fieldset>

                    <div class="layui-inline">
                        <div class="layui-form-item">
                            <label class="layui-form-label">提款金额:</label>
                            <div class="layui-input-inline">
                                <input type="text" name="money" lay-verify="required|number" autocomplete="off" value=""
                                       placeholder="请输入提款金额"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">支付方式:</label>
                            <div class="layui-input-inline">
                                <select name="pay_type" lay-verify="required" lay-search="" lay-filter="pay_type">
                                    <option value="">请选择</option>
                                    @foreach($payTypes as $key=>$name)
                                        <option value="{{$key}}"
                                                @if($agent->pay_type==$key) selected @endif>{{$name}}</option>
                                    @endforeach
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">支付账号:</label>
                            <div class="layui-input-inline">
                                <input type="text" name="account" lay-verify="required" autocomplete="off"
                                       value="{{ old('account',$agent->account) }}"
                                       placeholder="请输入支付账号"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item" id="account_address"
                             @if($agent->pay_type=='bankcard') style="display: block"
                             @else style="display: none" @endif>
                            <label class="layui-form-label">开户地址:</label>
                            <div class="layui-input-inline">
                                <input type="text" name="account_address" lay-verify=""
                                       autocomplete="off"
                                       value="{{ old('account_address',$agent->account_address) }}"
                                       placeholder="请输入开户地址"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item" id="account_real_name">
                            <label class="layui-form-label">开户姓名:</label>
                            <div class="layui-input-inline">
                                <input type="text" name="account_real_name" lay-verify="required"
                                       autocomplete="off"
                                       value="{{ old('account_real_name',$agent->account_real_name) }}"
                                       placeholder="请输入开户姓名"
                                       class="layui-input">
                            </div>
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <button class="layui-btn" lay-submit="" lay-filter="demo1">提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </form>
        @endif
    </div>
@endsection

@section('scripts')
    <script>
        /*$(function () {
            var userType ={{\Auth::user()->type}} ;
            if (userType !== 1) {
                layer.confirm('非代理账户，代理提款功能不可用！', {
                    btn: ['确认']
                }, function (index) {
                    history.go(-1);
                });

            }

        });*/
        layui.use('form', function () {
            var form = layui.form;
            form.on('select(pay_type)', function (data) {
                var value = data.elem.value;

                if (value === 'bankcard') {
                    document.getElementById('account_address').style.display = 'block';
                } else {
                    document.getElementById('account_address').style.display = 'none';
                }

            });
        });

    </script>
@endsection